﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Ultima.Xna.Graphics.UI.Gumps
{
    public class GumpScrollbar : GumpEntry
    {
        Texture2D _upArrowTexture;
        Texture2D _upArrowTexturePressed;
        Texture2D _downArrowTexture;
        Texture2D _downArrowTexturePressed;
        Texture2D _scrollBarTexture;
        Texture2D _bgTexture;

        public override Vector2 Position
        {
            get
            {
                if (Parent != null && _bgTexture != null)
                {
                    return new Vector2(Parent.Size.X - _bgTexture.Width, 0);
                }

                return base.Position;
            }
            set
            {
                base.Position = value;
            }
        }

        public override Vector2 Size
        {
            get
            {
                if (Parent != null && _bgTexture != null)
                {
                    return new Vector2(_bgTexture.Width, Parent.Size.Y);
                }

                return base.Size;
            }
            set
            {
                base.Size = value;
            }
        }

        public Texture2D UpArrowTexture
        {
            get { return _upArrowTexture; }
        }

        public Texture2D UpArrowTexturePressed
        {
            get { return _upArrowTexturePressed; }
        }

        public Texture2D DownArrowTexture
        {
            get { return _downArrowTexture; }
        }

        public Texture2D DownArrowTexturePressed
        {
            get { return _downArrowTexturePressed; }
        }

        public Texture2D ScrollBarTexture
        {
            get { return _scrollBarTexture; }
        }

        public Texture2D BgTexture
        {
            get { return _bgTexture; }
        }

        public GumpScrollbar(Game game)
            : base(game)
        {

        }

        public override void Initialize()
        {
            base.Initialize();
            
            _upArrowTexture = Data.Gumps.CreateTexture(Game.GraphicsDevice, 0xFA);
            _upArrowTexturePressed = Data.Gumps.CreateTexture(Game.GraphicsDevice, 0xFB);
            _downArrowTexture = Data.Gumps.CreateTexture(Game.GraphicsDevice, 0xFC);
            _downArrowTexturePressed = Data.Gumps.CreateTexture(Game.GraphicsDevice, 0xFD);
            _scrollBarTexture = Data.Gumps.CreateTexture(Game.GraphicsDevice, 0xFE);
            _bgTexture = Data.Gumps.CreateTexture(Game.GraphicsDevice, 0x100);
        }

        public override void Draw(GameTime gameTime)
        {
            Manager.Renderer.Render(this);

            base.Draw(gameTime);
        }
    }
}
